home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / tapest / tapest.lzh / TAPEST.C < prev    next >
Text File  |  1991-01-29  |  3KB  |  159 lines

  1. /*
  2.  *    TAPESTRY
  3.  *        original idea from A.K.Dudeny's "Computer Recreation"
  4.  *
  5.  *                         (C) 1990 Waku Factory
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <time.h>
  11. #include <egb.h>
  12. #include <mos.h>
  13.  
  14. #define pset(x,y,col) putVRAMb( y*1024+x, col, 0x10c )
  15. #define put(x,y,c) pset((x+w/2),(y+h/2),c ) 
  16.  
  17. #define fn( x,y ) ((x*x+y*y)*mag + pofs )
  18. #define fp( x,y ) put((x),(y),fn((x),(y))%col)
  19.  
  20. static char name[] = "TAPESTRY  (C) 1990 Waku Factory" ;
  21.  
  22. char gwork[1540] ;
  23. char mwork[4096] ;
  24. short param[20] ;
  25. int w, h, hw ;
  26. int s ;
  27.  
  28. extern void putVRAMb() ;
  29. extern int getopt() ;
  30. extern char *optarg ;
  31. extern void palette() ;
  32.  
  33. void main(ac,av)
  34. int ac ;
  35. char **av ;
  36. {
  37.     int mag,col,b,pal ;
  38.     int pofs,dm ;
  39.     
  40.     col = 256 ;
  41.     mag = 2 ;
  42.     pal = 0 ;
  43.     s = 0 ;
  44.     pofs = clock() % 256 ;
  45.     dm = 1 ;
  46.     
  47.     while( (b = getopt( ac,av, "c:b:ps:d:" ) ) != EOF ) 
  48.     switch( b ) {
  49.     case 'c':
  50.         col = atoi( optarg ) ;
  51.         break ;
  52.     case 'b':
  53.         mag = atoi( optarg ) ;
  54.         break ;
  55.     case 'p':
  56.         pal = 1 ;
  57.         break ;
  58.     case 's':
  59.         s = atoi( optarg ) ;
  60.         break ;
  61.     case 'd':
  62.         dm = atoi( optarg ) ;
  63.         break ;
  64.     case '?':
  65.         puts( "USAGE : tapest -c<colors> -b<dot> -s<speed> -d<divide> -p" ) ;
  66.         exit( 0 ) ;
  67.     }
  68.     w = 640 / mag ;
  69.     h = 480 / mag ;
  70.     hw = h / 2 - 1 ;
  71.     
  72.     EGB_init( gwork, 1536 ) ;
  73.     EGB_resolution( gwork , 0, 12 ) ;
  74.     EGB_displayPage( gwork, 0, 3 ) ;
  75.     EGB_displayStart(gwork, 2, mag, mag ) ;
  76.     MOS_start( mwork, 4096 ) ;
  77.     MOS_resolution( 0,12 ) ;
  78.     MOS_disp( 0 ) ;
  79.     if( pal ) 
  80.         palette( 1, col-1, 0,360, 1.0,0.0, 1.0,0.0 );
  81.     
  82.     param[0] = 1;
  83.     mag = dm ;
  84.     for( ;;) {
  85.         if( tap( mag, col, pofs ) < 0 )
  86.             break ;
  87.         if( (mag += dm ) >= 256 ) {
  88.             mag = dm ;
  89.             pofs++ ;
  90.         }    
  91.     }
  92.  
  93.     MOS_end() ;
  94. }
  95.  
  96. void wait()
  97. {
  98.     int i, j ;
  99.     
  100.     for( i = 0 ; i < s ; i++ ) 
  101.         for( j = 0 ; j < 50 ; j++ ) ;
  102. }
  103.  
  104. int tap( mag, col,pofs ) 
  105. int mag,col,pofs ;
  106. {
  107.     int x,y ;
  108.     int i, c ;
  109.     
  110.     for( i = 1 ; i <= hw ; i++ ) {
  111.         for( x = 0 ; x <= i ; x++ ) {
  112.             fp( x, i ) ;
  113.             fp( -x, i ) ;
  114.             fp( x, -i ) ;
  115.             fp( -x, -i ) ;
  116.             wait() ;
  117.         }
  118.         for( y = i ; y >= 0 ; y-- ) {
  119.             fp( i, y ) ;
  120.             fp( -i, y ) ;
  121.             fp( i, -y ) ;
  122.             fp( -i, -y ) ;
  123.             wait() ;
  124.         }
  125.         if( chkmos() ) return -1 ;
  126.     }
  127.     for( i = hw+1 ; i <= w/2-1 ; i++ ) {
  128.         for( y = 0 ; y <= hw ; y++ ) {
  129.             fp( i, y ) ;
  130.             fp( -i, y ) ;
  131.             fp( i, -y ) ;
  132.             fp( -i, -y ) ;
  133.             wait() ;
  134.         }
  135.         MOS_rdpos( &c,&x,&y ) ;
  136.         if( chkmos() ) return -1 ;
  137.     }
  138.     return 0 ;
  139. }
  140.  
  141. chkmos()
  142. {
  143.     int c,x,y ;
  144.     MOS_rdpos( &c, &x, &y ) ;
  145.     if( c == 0 ) return 0 ;
  146.     if( c != 1 ) return 1 ;
  147.     while( c == 1 ) {
  148.         MOS_rdpos( &c, &x, &y ) ;
  149.     }
  150.     while( c != 1 ) {
  151.         MOS_rdpos( &c, &x, &y ) ;
  152.     }
  153.     while( c == 1 ) {
  154.         MOS_rdpos( &c, &x, &y ) ;
  155.     }
  156.     return 0 ;
  157. }
  158.  
  159.